//
//  HOPotalLocationViewController.m
//  微度报修
//
//  Created by foguo-mac-1 on 6/29/16.
//  Copyright © 2016 WeiDu. All rights reserved.
//

#import "HOPotalLocationViewController.h"
#import "HOConstants.h"
#import "HOPotalPointEntity.h"

@interface HOPotalLocationViewController ()

@end

@implementation HOPotalLocationViewController

- (void)viewDidLoad {
	[super viewDidLoad];
	// Do any additional setup after loading the view.
	[self initTableView];
	[self requestDataWithMaxId:1];
}

- (void)viewWillAppear:(BOOL)animated
{
	[super viewWillAppear:animated];
	[self setNavigationItemTitle:NSLocalizedString(@"巡查点明细", @"巡查点明细")];
	
}

- (void)requestDataWithMaxId:(int)maxId
{
	[self sendRequestWithParams:@{kHO_FIELD_Action:kHO_ACTION_InspectPoint,
								  kHO_FIELD_MaxID:[NSNumber numberWithInt:maxId]}];
}

- (void)pullUpToRefresh
{
	HOPotalPointEntity *entity = [self.tableViewDataList lastObject];
	if(entity)
	{
		[self requestDataWithMaxId:entity.pointId];
	}
	else
	{
		[self requestDataWithMaxId:1];
	}
}


#pragma mark - -- UITableViewDelegate/UITableViewDataResource implement methods
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
	return CELL_HEIGHT;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
	return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
	NSInteger count = [self.tableViewDataList count];
	[self updateNoResultView:count];;
	return count;
}


- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
	return SECTION_PADDING / 2;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
	static NSString *HOTableViewCell = @"HOTableViewCell";
	UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:HOTableViewCell];
	if(cell == nil)
	{
		cell = [[[UITableViewCell alloc]
				 initWithStyle:UITableViewCellStyleDefault
				 reuseIdentifier: HOTableViewCell] autorelease];
	}
	HOPotalPointEntity *entity = [self.tableViewDataList objectAtIndex:indexPath.row];
	cell.textLabel.text = entity.pointName;
	return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
	HOPotalPointEntity *entity = [self.tableViewDataList objectAtIndex:indexPath.row];
	[self.delegate didSelectPotalPoint:entity];
	[tableView deselectRowAtIndexPath:indexPath animated:YES];
	[self goBack];
	
}
#pragma mark

#pragma mark -- tool
- (void)didReceiveMemoryWarning {
	[super didReceiveMemoryWarning];
	// Dispose of any resources that can be recreated.
}


- (void)requestDidSuccessWithResponse:(HOBaseResponseEntity *)response
{
	if([response isEqualAction:kHO_ACTION_InspectPoint])
	{
		for(int i = 0; i < [response.dataNode count]; i ++)
		{
			NSDictionary *dic = [response.dataNode objectAtIndex:i];
			HOPotalPointEntity *entity = [[HOPotalPointEntity alloc] init];
			[entity parseDic:dic];
			[self.tableViewDataList addObject:entity];
			[entity release];
		}
		[baseTableview reloadData];
	}
}

- (void)dealloc
{
	self.delegate = nil;
	[super dealloc];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
